﻿using System;
using Game.Map.Internal;

namespace Game.Map
{
    public static class MapFieldFactory
    {
        public static event EventHandler<MapFieldFactoryEventArgs> SetupField;

        public static IMapField CreateField(
            IGameMap map,
            double coordinateX,
            double coordinateY)
        {
            var field = new MapField(coordinateX, coordinateY);
            FireSetupField(map, field);
            return field;
        }

        internal static void FireSetupFields(
            IGameMap map)
        {
            foreach (var field in map.Fields)
            {
                FireSetupField(map, field);
            }
        }

        internal static void FireSetupField(
            IGameMap map,
            IMapField field)
        {
            if (SetupField != null)
            {
                SetupField(field, new MapFieldFactoryEventArgs(map, field));
            }
        }
    }

    public class MapFieldFactoryEventArgs : EventArgs
    {
        readonly IGameMap _map;
        readonly IMapField _mapField;

        public MapFieldFactoryEventArgs(IGameMap map, IMapField field)
        {
            _map = map;
            _mapField = field;
        }

        public IMapField MapField
        {
            get { return _mapField; }
        }

        public IGameMap GameMap
        {
            get { return _map; }
        }
    }

}
